using System;
using System.Collections.Generic;
using System.Text;

namespace GameOfLife
{
    public class RuleSet
    {
        int[] dead2alive, alive2alive;


        /// <summary>
        /// The constructor for Ruleset
        /// 
        ///  the parameters specify the number of neighbors
        ///   that will transition to a living cell
        ///   during the next time step
        /// 
        ///   For example Conway's rules would be constructed
        ///    with:
        /// 
        ///    A Dead cell with 3 living neighbors
        ///    A living cell with 2 living neighbors
        ///    A living cell with 3 living neighbors 
        ///    
        ///    new RuleSet(new int[1] { 3 }, new int[2] { 2, 3 })
        /// 
        /// </summary>
        /// <param name="dead2alive"></param>
        /// <param name="alive2alive"></param>
        public RuleSet(int[] dead2alive, int[] alive2alive)
        {
            this.dead2alive = dead2alive;
            this.alive2alive = alive2alive;
        }


        /// <summary>
        /// This method is called to determine if a cell should be alive
        ///  during the next time step.
        /// </summary>
        /// <param name="isAlive">true if the cell is currently alive, false if dead</param>
        /// <param name="numNeighbors">the number of living neighbors adjacent to the cell</param>
        /// <returns></returns>
        public bool NextState(bool isAlive, int numNeighbors)
        {
            int[] arr = isAlive ? alive2alive : dead2alive;
            foreach (int a in arr) if (a == numNeighbors) return true;
            return false;
        }
    }
}
